home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
JumpingFish.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
5KB
|
160 lines
class JumpingFish extends SSObject
{
var classID = SSGlobal.CLSID_MOBILEOBJECT;
var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
var assetID = "JumpingFish";
var waitOffset = 0;
var jumpStrength = 500;
var waitSyncTime = 4;
var exitedSceneAt = 0;
var immobilizeTime = 5;
var gravity = SSGlobal.GRAVITY;
var waitTime = 0;
var healthValue = -0.2;
var collision = false;
var immobilized = 0;
var editor_isItem = true;
var editor_name = "JumpingFish";
var editor_args_names = ["jumpStrength","waitSyncTime","waitOffset"];
var editor_args_values = [JumpingFish.prototype.jumpStrength,JumpingFish.prototype.waitSyncTime,JumpingFish.prototype.waitOffset];
var editor_args_types = ["number","number","number"];
var editor_args_options = [[100,1000,50],[0,15,0.1],[-5,5,0.1]];
var editor_args_descriptions = ["","",""];
var editor_args_mode = [0,0,0];
var editor_args_component = ["NumericStepper","NumericStepper","NumericStepper"];
function JumpingFish(jumpStrength, waitSyncTime, waitOffset)
{
super();
if(jumpStrength != null)
{
this.jumpStrength = jumpStrength;
}
if(waitSyncTime != null)
{
this.waitSyncTime = waitSyncTime;
}
if(waitOffset != null)
{
this.waitOffset = waitOffset;
}
}
function onAddToWorld()
{
}
function onAddToScene()
{
this.getUpdates();
if(this.launchY)
{
this.y = this.launchY;
this.syncTime();
this.target._visible = false;
}
if(this.immobilized)
{
this.immobilized = Math.max(this.immobilized - (this.world.time - this.exitedSceneAt),0);
}
}
function syncTime()
{
this.waitTime = this.waitSyncTime - (this.world.time + this.waitOffset) % this.waitSyncTime;
}
function onRemoveFromScene()
{
this.cancelUpdates();
this.exitedSceneAt = this.world.time;
}
function update(elapsed)
{
if(this.waitTime)
{
if(this.immobilized)
{
if(this.immobilized = Math.max(this.immobilized - elapsed,0))
{
return undefined;
}
this.syncTime();
}
var _loc3_ = this.waitTime;
if((this.waitTime -= elapsed) <= 0)
{
this.waitTime = 0;
this.y = this.launchY;
this.velocity.y = - this.jumpStrength;
this.target._rotation = 90;
this.splash();
this.target._visible = true;
}
}
else
{
this.velocity.y += this.gravity * elapsed;
this.moveBy(0,this.velocity.y * elapsed,0);
this.checkCollisions(elapsed);
if(this.velocity.y > 0 && this.launchY && this.y > this.launchY)
{
this.velocity.y = 0;
this.syncTime();
this.target._visible = false;
this.splash();
}
else
{
this.target._rotation += ((this.velocity.y <= 0 ? 90 : -180) - this.target._rotation) * elapsed;
}
}
}
function splash()
{
var _loc2_ = new SSParticle("splash",2,new Vector(0,0,0));
GameSound.playSound("splash");
_loc2_.x = this.x;
_loc2_.y = this.launchY + this.radius;
this.world.addObject(_loc2_);
}
function checkCollision(obj)
{
var _loc3_ = undefined;
switch(obj.classID & 4294901760)
{
case SSGlobal.CLSID_SHAPE:
if(this.launchY == null && (_loc3_ = SSCollision.sweepSphereToStaticShape(this,obj)) && _loc3_.edge.attributes.water)
{
this.collisionMask = SSGlobal.CLSID_MAINCHAR;
this.launchY = _loc3_.point.y;
}
break;
case SSGlobal.CLSID_MAINCHAR:
if(SSCollision.sweepSphereToSphere(this,obj,true))
{
return this.onCollision(obj);
}
break;
}
}
function onCollision(obj)
{
if(this.waitTime || this.immobilized)
{
return undefined;
}
if((obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
{
if(obj.shield || obj.classID == SSGlobal.CLSID_VEHICLE)
{
this.immobilize();
}
else
{
obj.shiftHealth(this.healthValue,this);
}
}
}
function immobilize(obj)
{
this.velocity.y = -200;
this.immobilized = this.immobilizeTime;
}
}